<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>jQuery Ajax</title>
    <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js"></script>
</head>
<body>
<div>
    请输入邮箱：<input type="text" id="email" value="user01"/>
</div>
<div>
    请输入密码：<input type="password" id="password" value="123456"/>
</div>
<div>
    <button id="btn1">登录</button>
</div>


<div id="result">

</div>
</body>
<script type="text/javascript">
    $(document).ready(function () {
        $("#btn1").click(function () {
            var email = $("#email").val();
            var pwd = $("#password").val();
            console.log(email, pwd);

            $.ajax({
                type: 'post',
                url: "http://59.110.168.33:8081/user/login",
                // url: 'http://localhost:8081/user/login',
                contentType: 'application/x-www-form-urlencoded',
                dataType: 'json',
                data: {
                    email: email,
                    passWord: pwd
                },
                success: function (data) {
                    console.log(data);
                    if (data.status == 1) {
                        localStorage.setItem("token", data.token);
                        $("#result").text("登录成功!");
                        window.location.href = "./order.html";
                    } else {
                        alert("登录失败：" + data.msg);
                        $("#result").text(data.msg);
                    }
                },
                error: function () {
                    alert("网络错误")
                    $("#result").text("网络错误!");
                }
            });
        });
    });
</script>
</html>